package co.yixiang.modules.shop.rest;

import co.yixiang.aop.log.Log;
import co.yixiang.modules.shop.domain.YxStoreProductCheckmake;
import co.yixiang.modules.shop.service.YxStoreProductCheckmakeService;
import co.yixiang.modules.shop.service.YxStoreProductService;
import co.yixiang.modules.shop.service.dto.YxStoreProductCheckmakeQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author frq
 * @date 2020-07-17
 */
@Api(tags = "盘点系统")
@RestController
@RequestMapping("/api/yxStoreProductCheckmake")
public class YxStoreProductCheckmakeController {
    @Autowired
    private YxStoreProductCheckmakeService yxStoreProductCheckmakeService;

    @Autowired
    private YxStoreProductService YxStoreProductService;

    @GetMapping("/findByBarCode")
    @Log("查询商品信息")
    @ApiOperation("查询商品信息")
    public ResponseEntity<Object> findByBarCode(@RequestParam String barCode) {
        return new ResponseEntity<>(YxStoreProductService.findByBarCode(barCode), HttpStatus.OK);
    }

    @GetMapping("/getYxStoreProductCheckmakes")
    @Log("查询盘点信息")
    @ApiOperation("查询盘点信息")
    public ResponseEntity<Object> getYxStoreProductCheckmakes(YxStoreProductCheckmakeQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(yxStoreProductCheckmakeService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @PostMapping("/create")
    @Log("保存盘点信息")
    @ApiOperation("保存盘点信息")
    public ResponseEntity<Object> create(@Validated @RequestBody YxStoreProductCheckmake resources) {
        return new ResponseEntity<>(yxStoreProductCheckmakeService.create(resources), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改盘点信息")
    @ApiOperation("修改盘点信息")
    public ResponseEntity<Object> update(@Validated @RequestBody YxStoreProductCheckmake resources) {
        yxStoreProductCheckmakeService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除盘点信息")
    @ApiOperation("删除盘点信息")
    @GetMapping("/delete/{id}")
    public ResponseEntity<Object> delete(@PathVariable Integer id) {
        yxStoreProductCheckmakeService.deleteAll(id);
        Map<String, String> map = new HashMap<>();
        map.put("msg", "操作成功");
        return new ResponseEntity<>(map, HttpStatus.OK);
    }
}